/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package queenb.web.controller;

import java.util.ArrayList;
import java.util.List;
import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem;
import queenb.net.entitybean.K330;
import queenb.web.store.K330Store;
import queenb.web.util.ComboboxUtil;
import queenb.web.util.SessionProvider;
import queenb.web.util.Util;

/**
 *
 * @author Nguyen Hung
 */
public class K330Controller extends QueenbController{
    private int pk330;
    private String kv331;
    private String kv332;
     private String kv333;
     private int k0000;
    K330Store k330Store;
   private boolean flagCheck;
    private List<SelectItem> comboK300 = new ArrayList<SelectItem>();
     private List<SelectItem> comboK330 = new ArrayList<SelectItem>();
    
    public K330Controller()
    {
        k330Store = new K330Store();
        Object action = getRequest().getParameter("action");
        Object pk330Object = getRequest().getParameter("pk330");
        if(action != null)
        {
            if(action.equals("edit"))
            {
                this.pk330 = Util.parseInt(pk330Object);
                getDetailEditK350(pk330);
            }
        }
    }
     public void getDetailEditK350(int id) {
        try {
            List<K330> listK350Edit = getListAllK330();
            if (listK350Edit.size() > 0) {
                for (int i = 0; i < listK350Edit.size(); i++) {
                    if (listK350Edit.get(i).getPk330() == id) {
                        this.kv331 = listK350Edit.get(i).getKv331();
                        this.kv332 = listK350Edit.get(i).getKv332();
                        this.kv333 = listK350Edit.get(i).getKv333();
                        System.out.println("----------K300------------"+ kv333);
                        if(kv333 != null){
                            if(kv333.equals("K")){
                                k0000 = 1;
                            }else{
                                k0000 = 2;
                            }
                        }
                        break;
                    }
                }
            }
        } catch (Exception ex) {
            System.out.println("Error when getDetailEditN850. ERROR CODE: " + ex.getMessage());
        }
    }
     public void changeK300(ActionEvent ev){
        try {
            SessionProvider.setSessionMapValue("K300BOOLEAN", flagCheck);
        } catch (Exception e) {
        }
    }
     public List<K330> getListAllK330() {

        try {
              if (SessionProvider.getSessionMapValue("K300BOOLEAN") != null) {
                if (SessionProvider.getSessionMapValue("K300BOOLEAN").equals(true)) {
                    kv333 = "C";
                } else {
                    kv333 = "K";
                }
            } else {
                kv333 = "K";
            }
            List<K330> list = k330Store.getListK350All(getLogin().getModule(), getLogin().getCompanyNo(),kv333, getLogin().getUserName());
            System.out.println("--------+++++++" + list.get(0).getKv331());
            return list;
        } catch (Exception ex) {
            System.out.println(ex);
            return null;
        }

    }
    public void updateK330(){
        try {
             if(k0000 == 1){
                kv333 = "K";
            }else{
                kv333 = "C";
            }
            int count = k330Store.updateK350(pk330,this.kv331,kv332,kv333, getLogin().getModule(),getLogin().getCompanyNo(),getLogin().getUserName());
             if (count > 0) {
                showGlobalReport(true, getResourceString("success"));
            } else {
                showGlobalReport(true, getResourceString("error"));
            }
       
        
        sendRedirectUrlTab("setting.jsp?tab=header20&link20="+Util.convertMD5(getRequest().getRequestURI()));
        } catch (Exception e) {
        }
    }

    /**
     * @return the pk330
     */
    public int getPk330() {
        return pk330;
    }

    /**
     * @param pk330 the pk330 to set
     */
    public void setPk330(int pk330) {
        this.pk330 = pk330;
    }

    /**
     * @return the kv331
     */
    public String getKv331() {
        return kv331;
    }

    /**
     * @param kv331 the kv331 to set
     */
    public void setKv331(String kv331) {
        this.kv331 = kv331;
    }

    /**
     * @return the kv332
     */
    public String getKv332() {
        return kv332;
    }

    /**
     * @param kv332 the kv332 to set
     */
    public void setKv332(String kv332) {
        this.kv332 = kv332;
    }

    /**
     * @return the kv333
     */
    public String getKv333() {
        return kv333;
    }

    /**
     * @param kv333 the kv333 to set
     */
    public void setKv333(String kv333) {
        this.kv333 = kv333;
    }

    /**
     * @return the k0000
     */
    public int getK0000() {
        return k0000;
    }

    /**
     * @param k0000 the k0000 to set
     */
    public void setK0000(int k0000) {
        this.k0000 = k0000;
    }

    /**
     * @return the comboK300
     */
    public List<SelectItem> getComboK300() {
        ComboboxUtil combo = new ComboboxUtil();
        return combo.getlistCombK300("C");
    }

    /**
     * @param comboK300 the comboK300 to set
     */
    public void setComboK300(List<SelectItem> comboK300) {
        this.comboK300 = comboK300;
    }

    /**
     * @return the comboK330
     */
    public List<SelectItem> getComboK330() {
          ComboboxUtil combo = new ComboboxUtil();
        return combo.getlistCombK330("C");
    }

    /**
     * @param comboK330 the comboK330 to set
     */
    public void setComboK330(List<SelectItem> comboK330) {
        this.comboK330 = comboK330;
    }

    /**
     * @return the flagCheck
     */
    public boolean isFlagCheck() {
        return flagCheck;
    }

    /**
     * @param flagCheck the flagCheck to set
     */
    public void setFlagCheck(boolean flagCheck) {
        this.flagCheck = flagCheck;
    }
}
